package cn.net.nit.ems.util;
import java.sql.*;
public class DBHelper {
	private static String driver = "com.mysql.jdbc.Driver";
	private static String url = "jdbc:mysql://localhost:3306/emsdb?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull";
	private static String user = "root";
	private static String pwd = "root";
	
	public static Connection getConnection() {
		Connection conn = null;
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, pwd);
			conn.setAutoCommit(false);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
    public static void close(Connection conn) {
    	if (conn != null) {
    		try {
    			conn.close();
    		} catch (SQLException e) {}
    		conn = null;
    	}
    }
    
    public static void close(Statement stmt, ResultSet rs) {
    	if (stmt != null) {
    		try {
    			stmt.close();
    		} catch (SQLException e) {}
    	}
    	if (rs != null) {
    		try {
    			rs.close();
    		} catch (SQLException e) {}
    	}
    }
}

